/**
 *@Description: store出口配置
 *@author: Wangsenyang
 *@Date: 2020/2/27
 */
import Vue from 'vue';
import Vuex from 'vuex';
import theme from './modules/theme';
import user from './modules/user';
import routerTabs from './modules/routerTabs';
import tree from './modules/tree';
import getters from './getters';
import flow from './modules/flow';

Vue.use(Vuex);

const queryParamsDefault = {
  dashboard: {
    dataSourceName: [],
    network: [],
    platform: [],
    applicationsystemcode: [],
    condition: '',
    deptId: [],
    pageNum: 1,
    timeFlag: 0,
  },
  accessObjManage: {
    objectType: [],
    dataRange: [],
    condition: '',
    pageNum: 1,
    timeFlag: 0,
  },
  accessObjInfo: {
    ACCESS_SYS_DIALECT_ID: '',
    accessSysId: '',
    diyComments: '',
    pageNum1: 1,
    pageNum2: 1,
    keyword: '',
    tabPosition: 'metadataManage',
    timeFlag: 0,
  },
  recyclingBins: {
    dataSourceName: [],
    network: [],
    applicationsystemcode: [],
    platform: [],
    deptId: [],
    condition: '',
    pageNum: 1,
    timeFlag: 0,
  },
  setting: {
    timeFlag: 0,
  },
  // 接入方对账单
  accessStatement: {
    resourceCode: '',
    sendTimeStart: '',
    sendTimeEnd: '',
    accountStatus: '',
    pageNum: 1,
    deptId: [],
    timeFlag: 0,
  },
}

const store = new Vuex.Store({
  state: {
    deptId: [],
    deptIdLess: [],
    routeFlag: '',
    fliterItemList: {
      network: {
        ready: false,
        data: [],
      },
      dataSourceName: {
        ready: false,
        data: [],
      },
      platform: {
        ready: false,
        data: [],
      },
      // 应用系统
      applicationsystemcode: {
        ready: false,
        data: [],
      },
      flow,
    },
    pageSize: 10,
    pageReady: false,
    queryParams: JSON.parse(JSON.stringify(queryParamsDefault)),
    schemaList: [], // 增量字段列表--数据源相关字段
    filterSchemaList: [],
    reduceSchemaList: [],
    checkSchemaList: [],
    userList: {}, // 数据调研列表
    regInfo: {}, // 正则
    matchType: [], // 自定义表
    matchflag: '0', // 表
    jrtype: '', // 接入源的类型----也是首页每一条数据的dataSourceName
    separator: '', // 分隔符
    isParquet: true, // 是否是parquet文件
    modeStyle: '', // 用户选择的接入方式
    noreData: [], // 非关系型数据 ftp结构化建立映射
    delimiter: '', // 非关系型分隔符
    jrstyle: '', // 用户标记的接入方式
    nums: true, // 映射关系
    hisdis: false, // 历史记录
    userInfo: {
      userName: '',
      roleName: '',
      userId: '',
    },
    taskParam: {
      keyword: '', // 查询条件
      taskPeriodType: [], // 任务类型
      status: [], // 任务状态
      priority: [], // 任务优先级
      time: [], // 任务开始时间
    },
    kettleTask: {
      status: [],
      time: [],
      taskName: '',
    },
    userThemes: '',
    thirdStepsData: {},
    clearStepsData: '',
    majorData: {
      dataObj: [],
      formSeledShow: {
        objectType: [],
        dataRange: [],
        platform: [],
        network: [],
        dataSourceName: [],
        applicationsystemcode: [],
      },
      keyword: '',
    },
    detailMajorData: {
      dataObj: [],
      formSeledShow: {
        objectType: [],
        dataRange: [],
        platform: [],
        network: [],
        dataSourceName: [],
        applicationsystemcode: [],
      },
      keyword: '',
    },
    batchMap: [], // 从后台得到批量的数据映射
    resourceName: '',
    userAuthority: {
      userInfo: [],
      dataAuthority: false,
      taskAuthority: false,
      administrator: false,
    },
    ftpFileInfo: {
      dataType: '',
      transferFormat: '',
      isZip: '',
      structFileContentFormat: '',
      structMatchRules: '',
      structZipPacketFormat: '',
      structZipPacketMatchRules: '',
      structSeparate: '',
      noStructFileContentFormat: '',
      noStructMatchRules: '',
      noStructZipPacketFormat: '',
      noStructZipPacketMatchRules: '',
      dataFtpFileAttrId: '',
    },
    ftpFjghSchemaList: [], // ftp非结构化 结构化 schemaList:[]
    structCreateTableFlag: '', // 迭代四新增，结构化、0创建新表，1利用旧表
    noStructCreateTableFlag: '', // 迭代四新增，非结构、0创建新表，1利用旧表
  },
  mutations: {
    setUserInfo(state, obj) {
      state.userInfo.userName = obj.userName;
      state.userInfo.roleName = obj.roleName;
      state.userInfo.userId = obj.userId;
    },
    setPageSize(state, pageSize) {
      state.pageSize = pageSize;
    },
    setPageReady(state) {
      state.pageReady = true;
    },
    setFilterItmeList(state, obj) {
      state.fliterItemList[obj.name].ready = true;
      state.fliterItemList[obj.name].data = obj.data;
    },
    selDept(state, ids) {
      state.deptId = ids;
    },
    setDeptIdLess(state, ids) {
      state.deptIdLess = ids;
    },
    setRouteFlag(state, obj) {
      state.routeFlag = flag;
    },
    setQueryParams(state, obj) {
      state.queryParams[obj.name] = obj.data;
    },
    resetQueryParam(state, obj) {
      const newObj = JSON.parse(JSON.stringify(queryParamsDefault));
      const changeObj = newObj[obj.resetData];
      changeObj.timeFlag = new Date().getTime();
      state.queryParams[obj.resetData] = changeObj;
    },
    setParamItem(state, obj) {
      for (const i in obj.data) { // 这里obj.data是一个数组，表示不需要重置的
        state.queryParams[obj.name][i] = obj.data[i];
      }
    },
    setSchemaList(state, obj) {
      state.schemaList = [];
      state.schemaList = obj;
      state.filterSchemaList = obj;
      state.reduceSchemaList = obj;
      state.checkSchemaList = obj;
    },
    setStructCreateFlag(state, flag) {
      state.structCreateTableFlag = '';
      state.structCreateTableFlag = flag;
    },
    setNoStructCreateFlag(state, flag) {
      state.noStructCreateTableFlag = '';
      state.noStructCreateTableFlag = flag;
    },
    // 数据调研列表
    setUserList(state, obj) {
      state.userList = {};
      state.userList = obj;
    },
    // 正则表达式
    setRegInfo(state, obj) {
      state.regInfo = {};
      state.regInfo = obj;
      state.matchflag = '0';
    },
    // 自定义表
    setMatchType(state, obj) {
      state.matchType = [];
      state.matchflag = '0';
      state.matchType = obj;
      state.matchflag = '1';
    },
    setJrtype(state, obj) {
      state.jrtype = '';
      state.jrtype = obj;
    },
    // 设置分隔符
    setSeparator(state, obj) {
      state.separator = '';
      state.separator = obj;
    },
    // 设置parquet文件
    setParquet(state, obj) {
      state.isParquet = false;
      state.isParquet = obj;
    },
    // 设置用户标记的接入方式
    setMode(state, obj) {
      state.modeStyle = '';
      state.modeStyle = obj;
    },
    // 非关系型建立的表
    setNoreData(state, obj) {
      state.noreData = [];
      state.noreData = obj;
    },
    // 非关系型分隔符
    setDelimiter(state, obj) {
      state.delimiter = '';
      state.delimiter = obj;
    },
    // 用户标记的接入方式
    setJrStyle(state, obj) {
      state.jrstyle = '';
      state.jrstyle = obj;
    },
    // 用户的颜色
    setThemes(state, obj) {
      state.userThemes = '';
      state.userThemes = obj;
    },
    // 设置映射关系
    setNums(state, obj) {
      state.nums = true;
      state.nums = obj;
    },
    setBatchMap(state, obj) {
      state.batchMap = [];
      state.batchMap = obj;
    },
    // 历史记录
    setHis(state, obj) {
      state.hisdis = false;
      state.hisdis = obj;
    },
    setThirdStepsData(state, obj) {
      state.thirdStepsData = obj;
    },
    setClearStepsData(state, obj) {
      state.clearStepsData = obj;
    },
    setMajorData(state, obj) {
      state.majorData = obj;
    },
    setTaskParam(state, obj) {
      state.taskParam = obj;
    },
    setDetailMajorData(state, obj) {
      state.detailMajorData = obj;
    },
    setResourceName(state, obj) {
      state.resourceName = obj;
    },
    setUserAuthority(state, obj) {
      if (obj.userInfo) {
        state.userAuthority.userInfo = obj.userInfo;
      }
      state.userAuthority.dataAuthority = !!obj.dataAuthority;
      state.userAuthority.taskAuthority = !!obj.taskAuthority;
      state.userAuthority.administrator = !!obj.administrator;
    },
    setFtpFileInfo(state, obj) {
      state.ftpFileInfo.dataType = obj.sjjg;
      state.ftpFileInfo.transferFormat = obj.csgs;
      state.ftpFileInfo.isZip = obj.isZip;
      state.ftpFileInfo.structFileContentFormat = obj.jgh_nrgs;
      state.ftpFileInfo.structMatchRules = obj.jgh_ppgz;
      state.ftpFileInfo.structZipPacketFormat = obj.jgh_ysbgs;
      state.ftpFileInfo.structZipPacketMatchRules = obj.jgh_ysbppgz;
      state.ftpFileInfo.structSeparate = obj.jgh_fgf;
      if (obj.jgh_nrgs == '01' || obj.jgh_nrgs == '02') {
        state.ftpFileInfo.structSeparate = obj.jgh_gjdmc;
      }
      state.ftpFileInfo.noStructFileContentFormat = obj.fjgh_nrgs;
      state.ftpFileInfo.noStructMatchRules = obj.fjgh_ppgz;
      state.ftpFileInfo.noStructZipPacketFormat = obj.fjgh_ysbgs;
      state.ftpFileInfo.noStructZipPacketMatchRules = obj.fjgh_ysbppgz;
      state.ftpFileInfo.dataFtpFileAttrId = obj.dataFtpFileAttrId;
    },
    setFtpFjghSchemaList(state, obj) {
      state.ftpFjghSchemaList = [];
      state.ftpFjghSchemaList = obj;
    },
  },
  modules: {
    theme,
    user,
    routerTabs,
    tree,
    flow,
  },
  getters,
});

export default store;
